<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Forum: {{forum.name}}</title>
    
<link rel="stylesheet" href="/gforumstatic/themes/default/css/base.css" type="text/css" media="screen">

</head>
<body>

{% include "user_panel.inc.html" %}

{% include "dev_note.inc.html" %}

<div class="wrapper gforum">

<h1>{{forum.name}}</h1>
<br/>

<div class="crumbs-holder">
  <ul class="crumbs">
    <li><a href="{{forumpath}}">Home</a></li>
    <li><span>»&nbsp;</span><a href="{{forumpath}}/f/{{forum.permalink}}"><strong>{{forum.name}}</strong></a></li>
  </ul>
</div>

{% if has_threads %}
<table class="forumtable">
  <thead>
    <tr>
      <th class="tcl">Thread</th>
      <th class="tc2">Messages</th>
      <th class="tc3">Views</th>
      <th class="tcr">Last post</th>
    </tr>
  </thead>
  <tbody>
  {% for thread in threads %}
  <tr class="rowodd">
    <td class="tcl">
      <div class="tclcon">
        <div>
          <a href="{{forumpath}}/t/{{thread.key.id}}/{{thread.permalink}}">{{thread.title}}</a> <span class="byuser">by {{thread.thread_starter.nick_name}}</span>
        </div>        
      </div>
    </td>
    <td class="tc2">{{thread.messages_number}}</td>
    <td class="tc3">{{thread.views_number}}</td>
    <td class="tcr">{{thread.last_message.create_date|date:"Y-m-d H:i"}}<span class="byuser"> by {{thread.last_message.user.nick_name}}</span></td>
  </tr>
  {% endfor %}  
  </tbody>
</table>
{% endif %}

{% if not has_threads %}
<br/><br/>
<div>
  <p>No threads</p>
</div>
{% endif %}

{% if user_authorized %}

<p>
<a href="#" id="create_thread_link">Create thread</a>
</p>

<div id="create_thread_form_div" class="hiddenElement">

  <form id="create_thread_form" action="{{forumpath}}/api/v1/create_thread" method="POST">
    <input type="hidden" id="forum_key_hi" name="forum_key" value="{{forum.key}}">
    <table>
      <tr>
        <td>Title:</td>
        <td><input id="thread_title_i" type="text" name="thread_title" /></td>
      </tr>
      <tr>
        <td>Message:</td>
        <td><textarea id="thread_message_ta" name="thread_message"></textarea></td>
      </tr>
    </table>
    <input type="button" id="create_thread_button" value="Create thread"/>
  </form>

</div>

{% endif %}

<!-- BEGIN SCRIPT SECTION -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script src="/gforumstatic/themes/default/js/gforum.js"></script>

{% if user_authorized %}

<script type="text/javascript">

$(document).ready(function() {
    setEventHandlers();
});

function setEventHandlers() {
    $('#create_thread_link').click(showHideCreateThreadForm);
    $('#create_thread_button').click(function() {
        gforum.createThread({
            forum_root:   '{{forumpath}}',
            forum_key:    $('#forum_key_hi').val(),
            thread_title: $('#thread_title_i').val(),
            message_text: $('#thread_message_ta').val(),
            callback: function(resp) {
                if (resp.status == 'ok') {
                    location.reload();
                } else {
                    alert(resp.errorMsg);
                }
            }
        });
    });
}

function showHideCreateThreadForm() {
    if ($('#create_thread_form_div').hasClass('hiddenElement')) {
        $('#create_thread_form_div').removeClass('hiddenElement');
        $('#create_thread_form_div').addClass('visibleElement');
        $('#create_thread_link').html('Hide');
    } else if ($('#create_thread_form_div').hasClass('visibleElement')) {
        $('#create_thread_form_div').removeClass('visibleElement');
        $('#create_thread_form_div').addClass('hiddenElement');
        $('#create_thread_link').html('Create thread');
    }
}
</script>
{% endif %}
<!-- END SCRIPT SECTION -->

</div>

</body>
</html>
